//
//  UIBarButtonItem+Extension.swift
//  MySinaWeibo
//
//  Created by eastriver on 16/10/3.
//  Copyright © 2016年 believewilliam. All rights reserved.
//

import UIKit
extension UIBarButtonItem {
    // 生成导航条右侧按钮的构造函数
    convenience init(title: String = "", imageName: String? = nil, target: Any?, action: Selector) {
       
        let editBtn = UIButton()
        editBtn.setTitle(title, for: .normal)
        editBtn.setTitleColor(UIColor.darkGray, for: .normal)
        editBtn.setTitleColor(UIColor.orange, for: .highlighted)
        editBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        if imageName != nil {
        
            editBtn.setImage(UIImage(named: imageName!), for: .normal)
            editBtn.setImage(UIImage(named:imageName! + "_highlighted"), for: .highlighted)
        }
        editBtn.sizeToFit()
        editBtn.addTarget(target, action: action, for: .touchUpInside)
        self.init()
        self.customView = editBtn
    }
}
